package com.lzm.ydpt.module.mall.utils;

import android.view.View;

import com.byt.framlib.baseadapter.rv.RvViewHolder;
import com.byt.framlib.commonwidget.OnNoDoubleClickListener;
import com.lzm.ydpt.R;
import com.lzm.ydpt.entity.mall.MallOrderBean;
import com.lzm.ydpt.entity.mall.ProductBean;
import com.lzm.ydpt.entity.mall.ShopGoods;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.DecimalFormat;
import java.util.List;

public class ProductUtil {

    // // 退款状态 1:申请退款，2:退款完成，3：退款关闭，4：退款失败
    public static String showRefundState(int state) {
        switch (state) {
            case 2:
                return "退款完成";
            case 3:
                return "退款关闭";
            case 4:
                return "退款失败";
            default:
                return "退款中";
        }
    }

    public static boolean isSubmitProduct(MallOrderBean orderBean) {
        if (orderBean.getRefund_state() == 1) {
            return false;
        } else {
            List<ShopGoods> list = orderBean.getGoods();
            for (ShopGoods shopGoods : list) {
                if (shopGoods.getRefund_state() == 1) {
                    return false;
                }
            }
        }
        return true;
    }

    public static double pausePrice(String price) {
        double tempPrice = 0.0;
        try {
            tempPrice = Double.parseDouble(price);
        } catch (Exception e) {
            tempPrice = 0;
        }
        return tempPrice;
    }

    /**
     * 组合商品和购物车数据
     *
     * @param list
     * @return
     */
    public static String goodRequestData(List<ShopGoods> list) {
        int size = list.size();
        JSONArray jsa = new JSONArray();
        for (int i = 0; i < size; i++) {
            try {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("option_id", list.get(i).getOption_id());
                jsonObject.put("quantity", list.get(i).getTotal());
                if (list.get(i).getCart_id() > 0) {
                    jsonObject.put("cart_id", list.get(i).getCart_id());
                }
                jsa.put(jsonObject);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        if (jsa.length() > 0) {
            return String.valueOf(jsa);
        } else {
            return "";
        }
    }

    /**
     * 添加数值千分符
     *
     * @param count 数值
     * @return 千分符字符串
     */
    public static String formatPriceNum(String count) {
        DecimalFormat demo = new DecimalFormat("#,##0.00");
        return demo.format(Double.parseDouble(count));
    }

    public static void initRVProductData(RvViewHolder rvViewHolder, int pos, ProductBean productBean){
        rvViewHolder.getView(R.id.img_product_common_ablum);
        rvViewHolder.setText(R.id.tv_product_name_home,"");
        rvViewHolder.setText(R.id.tv_product_coupon,"");
        rvViewHolder.setText(R.id.tv_product_recurrence,"");
        rvViewHolder.setText(R.id.tv_money_amout,"");
        rvViewHolder.setText(R.id.tv_product_sell_num,"");

    }
}